home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / perl / mac-perl / gs_102st.bin / GUSI / TFileSpec.h / TFileSpec.h
Encoding:
C/C++ Source or Header  |  1993-01-16  |  5.0 KB  |  185 lines  |  [TEXT/MPS ]

  1. /*********************************************************************
  2. Project    :    GUSI                -    Grand Unified Socket Interface
  3. File        :    TFileSpec.h        -    C and C++ routines to deal with path names
  4. Author    :    Matthias Neeracher
  5. Started    :    06Jun92                                Language    :    MPW C/C++
  6. Modified    :    08Sep92    MN    Permission flags were the wrong way around                
  7.                 12Sep92    MN    Renamed                
  8.                 15Nov92    MN    Forgot a few consts
  9.                 15Nov92    MN    Renamed once again
  10.                 15Nov92    MN    Made suitable for use from C programs
  11.                 08Dec92    MN    Made Default() public
  12.                 03Jan93    MN    Prevent multiple includes
  13.                 15Jan93    MN    IsParentOf, operator ==
  14. Last        :    15Jan93
  15. *********************************************************************/
  16.  
  17. #ifndef _TFILESPEC_
  18. #define _TFILESPEC_
  19.  
  20. /* These routines run both under System 7 and under older systems. */
  21.  
  22. #include <Files.h>
  23.  
  24. #ifdef __cplusplus
  25.  
  26. /************************** The C++ only interface ***************************/
  27.  
  28. class TFileSpec : public FSSpec {
  29.     static OSErr    error;
  30.     static short    curVol;
  31.     static long        curDir;
  32.     
  33. public:
  34.     // Return last error
  35.     static OSErr        Error()                            {    return error;        }
  36.     
  37.     // Change current directory
  38.     static OSErr        ChDir(const TFileSpec & spec);
  39.  
  40.     // Set to current directory
  41.     OSErr    Default();
  42.     
  43.     TFileSpec()                                                                {}
  44.  
  45.     // Construct from FSSpec
  46.     TFileSpec(const FSSpec & spec, Boolean useAlias = false);
  47.  
  48.     // Construct from components
  49.     TFileSpec(short vRefNum, long parID, ConstStr31Param name, Boolean useAlias = false);
  50.     
  51.     // Construct from working directory & file name
  52.     TFileSpec(short wd, ConstStr31Param name, Boolean useAlias = false);
  53.     
  54.     // Construct from full or relative path
  55.     TFileSpec(const char * path, Boolean useAlias = false);
  56.     
  57.     // Give full pathname
  58.     char *    FullPath() const;
  59.     
  60.     // Give path relative to current directory
  61.     char *    RelPath() const;        
  62.     
  63.     // Give information about the current object. If dirInfo is true, give information
  64.     //   about the current object's directory.
  65.     OSErr        CatInfo(CInfoPBRec & info, Boolean dirInfo = false) const;    
  66.     
  67.     // If object is an alias file, resolve it. If gently is true, nonexisting files
  68.     //   are tolerated.
  69.     OSErr        Resolve(Boolean gently = true);     
  70.  
  71.     // Resolve an existing object for which we already have a CInfoPBRec
  72.     OSErr        Resolve(const CInfoPBRec & info); 
  73.     
  74.     // true if object exists
  75.     Boolean    Exists() const;
  76.     
  77.     // true if object is a parent directory of other
  78.     Boolean    IsParentOf(const TFileSpec & other) const;
  79.     
  80.     // Replace object with its parent directory                                                    
  81.     TFileSpec     operator--();
  82.     
  83.     // Equivalent to calling -- levels times
  84.     TFileSpec     operator-=(int levels);
  85.     
  86.     // Equivalent to calling -= on a *copy* of the current object
  87.     TFileSpec    operator-(int levels) const;
  88.  
  89.     // Replace directory object by object with given name inside the directory
  90.     TFileSpec     operator+=(ConstStr31Param name);
  91.     TFileSpec    operator+=(const char * name);
  92.     
  93.     // Non-destructive version of +=
  94.     TFileSpec    operator+(ConstStr31Param name) const;
  95.     TFileSpec    operator+(const char * name) const;
  96.     
  97.     // Return the index-th object in the *parent* directory of the current object 
  98.     TFileSpec     operator[](short index) const;
  99.     
  100.     // Return if the two filespecs (not) are equal
  101.     Boolean        operator==(const TFileSpec & other) const;
  102.     Boolean        operator!=(const TFileSpec & other) const;
  103. };
  104.  
  105. inline Boolean IsFile(const CInfoPBRec & info)
  106. {
  107.     return !(info.dirInfo.ioFlAttrib & 0x10);
  108. }
  109.  
  110. inline Boolean IsAlias(const CInfoPBRec & info)
  111. {
  112.     return 
  113.         !(info.hFileInfo.ioFlAttrib & 0x10) && 
  114.         (info.hFileInfo.ioFlFndrInfo.fdFlags & (1 << 15));
  115. }
  116.  
  117. inline Boolean DirIsExported(const CInfoPBRec & info)
  118. {
  119.     return (info.hFileInfo.ioFlAttrib & 0x20);
  120. }
  121.  
  122. inline Boolean DirIsMounted(const CInfoPBRec & info)
  123. {
  124.     return (info.hFileInfo.ioFlAttrib & 0x08);
  125. }
  126.  
  127. inline Boolean DirIsShared(const CInfoPBRec & info)
  128. {
  129.     return (info.hFileInfo.ioFlAttrib & 0x04);
  130. }
  131.  
  132. inline Boolean HasRdPerm(const CInfoPBRec & info)
  133. {
  134. #ifdef OnceThisFieldIsDefined
  135.     return !(info.dirInfo.ioACUser & 0x02);
  136. #else
  137.     return !(info.dirInfo.filler2 & 0x02);
  138. #endif
  139. }
  140.  
  141. inline Boolean HasWrPerm(const CInfoPBRec & info)
  142. {
  143. #ifdef OnceThisFieldIsDefined
  144.     return !(info.dirInfo.ioACUser & 0x04);
  145. #else
  146.     return !(info.dirInfo.filler2 & 0x04);
  147. #endif
  148. }
  149.  
  150. extern "C" {
  151. #endif
  152.  
  153. /* Routines shared between C and C++ */
  154.  
  155. /* Convert a working directory & file name into a FSSpec. */
  156. OSErr WD2FSSpec(short wd, ConstStr31Param name, FSSpec * desc);
  157.  
  158. /* Convert a FSSpec into a full pathname. */
  159. char * FSp2FullPath(const FSSpec * desc);
  160.  
  161. /* Works like FSp2FullPath, but creates a *relative* pathname if the object
  162.    is contained in the current directory.  
  163. */
  164. char * FSp2RelPath(const FSSpec * desc);
  165.  
  166. /* Call GetCatInfo for file system object. */
  167. OSErr    FSpCatInfo(const FSSpec * desc, CInfoPBRec * info);
  168.  
  169. /* Return FSSpec of (vRefNum, parID) */
  170. OSErr FSpUp(FSSpec * desc);
  171.  
  172. /* Return FSSpec of file in directory denoted by desc */
  173. OSErr FSpDown(FSSpec * desc, ConstStr31Param name);
  174.  
  175. /* Return FSSpec of nth file in directory denoted by (vRefNum, parID) */
  176. OSErr FSpIndex(FSSpec * desc, short n);
  177.  
  178. /* Convert a pathname into a file spec. */
  179. OSErr Path2FSSpec(const char * path, FSSpec * desc);
  180.  
  181. #ifdef __cplusplus
  182. }
  183. #endif
  184. #endif
  185.